import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

// 根据当前路径自动确定顶部导航ID
// const getNavIdFromPath = (path) => {
//   if (!path || path === '/') return null
  
//   const match = path.match(/^\/[^/]+\/(\d+)/)
//   return match && match[1] ? parseInt(match[1]) : null
// }

// 创建store实例
export default new Vuex.Store({
  state: {
    navList: [],         // 导航列表（树形）
    baseNav: [],         // 导航列表（平面）
  },
  getters: {
    navList: state => state.navList,
    baseNav: state => state.baseNav,
    
  },
  mutations: {
    SET_NAV_LIST(state, list) {
      state.navList = list
    },
    SET_BASE_NAV(state, list) {
      state.baseNav = list
    },
    
  },
  actions: {
    // 设置导航列表
    setNavList({ commit }, list) {
      commit('SET_NAV_LIST', list)
    },
    // 设置基础导航
    setBaseNav({ commit }, list) {
      commit('SET_BASE_NAV', list)
    },
  }
})
